import localforage from 'localforage';
import settings from '../config/settings';
const siteTokenKey = settings.siteTokenKey;
const loginInfoKey = settings.loginInfoKey;
/**
 * 获取本地Token
 */
export const getToken = async (): Promise<string | null> => {
  return await localforage.getItem(siteTokenKey);
};

/**
 * 设置存储本地Token
 */
export const setToken = async (token: string): Promise<boolean> => {
  try {
    await localforage.setItem(siteTokenKey, token);
    return true;
  } catch (error) {
    return false;
  }
};

/**
 * 移除本地Token
 */
export const removeToken = async (): Promise<boolean> => {
  try {
    await localforage.removeItem(siteTokenKey);
    return true;
  } catch (error) {
    return false;
  }
};




export const getInfo = async (): Promise<any> => {
  return await localforage.getItem(loginInfoKey);
};


export const setInfo = async (info: any): Promise<boolean> => {
  try {
    await localforage.setItem(loginInfoKey, info);
    return true;
  } catch (error) {
    return false;
  }
};

export const removeInfo = async (): Promise<boolean> => {
  try {
    await localforage.removeItem(loginInfoKey);
    return true;
  } catch (error) {
    return false;
  }
};